package com.zwr.normal.sharemodel.juc;

import java.math.BigDecimal;

public class DecimalAccountLock implements DecimalAccount{
    private final Object lock = new Object();
    BigDecimal balance;
    public DecimalAccountLock(BigDecimal balance) {
        this.balance = balance;
    }
    @Override
    public BigDecimal getBalance() {
        return balance;
    }

    @Override
    public void withdraw(BigDecimal amount) {
        synchronized (lock){
            BigDecimal balance = this.getBalance();
            this.balance = balance.subtract(amount);
        }
    }
}
